package com.xAdmin.model;


import lombok.Data;


/**
 * @author Administrator
 */
@Data
public class Result<T> {

	/**
	 * 结果值
	 */
	private T data;

	/**
	 * 结果消息
	 */
	private String msg;

	/**
	 * 状态类型
	 */
	private Integer code;

	/**
	 * url
	 */
	private String url;



	public Result() {
	}

	public Result(Integer code, T data, String msg) {
		this.code = code;
		this.data = data;
		this.msg = msg;
	}
	public static <T> Result<T> succeed() {
		return of(null, DoResultType.success, "操作成功");
	}

	public static <T> Result<T> succeed(String msg) {
		return of(null, DoResultType.success, msg);
	}

	/**
	 * 成功
	 *
	 * @param data 返回值
	 * @param msg   信息
	 * @return {@code Result<T>}
	 * @author xiaYZ
	 * create time: 2023/04/04
	 * @see T
	 * @see String
	 * @see Result
	 **/
	public static <T> Result<T> succeed(T data, String msg) {
		return of(data, DoResultType.success, msg);
	}

	/**
	 * 成功
	 *
	 * @param data 数据值
	 * @return {@code Result<T>}
	 * @author xiaYZ
	 * create time: 2023/04/04
	 * @see T
	 * @see Result
	 **/
	public static <T> Result<T> succeed(T data) {
		return of(data, DoResultType.success, "请求成功");
	}

	/**
	 * 失败
	 *
	 * @return {@code Result<T>}
	 * @author xiaYZ
	 * create time: 2023/04/04
	 * @see T
	 * @see Result
	 **/
	public static <T> Result<T> fail() {
		return of(null, DoResultType.fail, "请求失败");
	}

	/**
	 * 失败
	 *
	 * @param msg 消息
	 * @return {@code Result<T>}
	 * @author xiaYZ
	 * create time: 2023/04/06
	 * @see String
	 * @see Result
	 **/
	public static <T> Result<T> fail(String msg) {
		return of(null, DoResultType.fail, msg);
	}


	public static <T> Result<T> of(T data, DoResultType stateType, String msg) {
		return new Result<>(stateType.getValue(), data, msg);
	}

}